
package com.suarte.core.hibernate;
import com.suarte.core.Employee;
import com.suarte.core.dao.EmployeeDao;
import java.util.List;

import org.appfuse.dao.hibernate.GenericDaoHibernate;

import org.springframework.stereotype.Repository;

/**
 * @date   Dec 20, 2010
 * @author Ggutierrez
 */
@Repository("employeeDao")
public class EmployeeDaoHibernate extends GenericDaoHibernate<Employee, Long> implements EmployeeDao {
    
    public EmployeeDaoHibernate() {
        super(Employee.class);
    }

    @Override
    public Employee get(Long id) {
        List<Employee> results = getHibernateTemplate().find("from Employee this join fetch this.user user where this.id = ?", id);
        return !results.isEmpty() ? results.get(0) : null;
    }

    public List<Employee> findByNames(String firstName) {
        return getHibernateTemplate().find("from Employee where firstName = ?", firstName);
    }

    public Employee get(String username) {
        List<Employee> results = getHibernateTemplate().find("from Employee this join fetch this.user user where user.username = ?", username);
        return !results.isEmpty() ? results.get(0) : null;
    }
}
